package com.kecheng.action;
import java.util.List;

import com.kecheng.dao.PinglunDao;
import com.kecheng.pojo.Pinglun;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.AllowedMethods;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 后台评论模块的增删改查，暂时留着
 * @author yunxin
 *
 */
@Action(value = "pinglun", results = {
		@Result(name = "findall", location = "/admin/product/pinglun.jsp"),
})
@AllowedMethods(value = {("regex:.*")})
public class PinglunAction {
	private List<Pinglun> pingluns;
	@Autowired
	private PinglunDao pinglunDao;
	private Pinglun pinglun;
	private String page;
	private int allpage;
	private int[]id;

	//查询所有评论
	public String findall(){
		if(page==null || "".equals(page)){
			page = "1";
		}
		pingluns = pinglunDao.findall(Integer.valueOf(page));
		allpage = pinglunDao.findallpage();
		return"findall";
	}
	//删除
	public String delete(){
		
		if (id != null) {
			for (int i = 0; i < id.length; i++) {
				Pinglun p=new Pinglun();
				p.setId(id[i]);
				pinglunDao.deletebyid(p);
			}
		}
		return findall();
	}
	
	public List<Pinglun> getPingluns() {
		return pingluns;
	}
	public void setPingluns(List<Pinglun> pingluns) {
		this.pingluns = pingluns;
	}

	public Pinglun getPinglun() {
		return pinglun;
	}
	public void setPinglun(Pinglun pinglun) {
		this.pinglun = pinglun;
	}
	public String getPage() {
		return page;
	}
	public void setPage(String page) {
		this.page = page;
	}
	public int getAllpage() {
		return allpage;
	}
	public void setAllpage(int allpage) {
		this.allpage = allpage;
	}
	public int[] getId() {
		return id;
	}
	public void setId(int[] id) {
		this.id = id;
	}
	
	

}
